class Solution {
public:
    int maxDiff(vector<int>& nums) {
        if(nums.size()<2)
            return 0;
        int min_num=nums[0];
        int max_diff=nums[1]-nums[0];
        for(int i=2;i<nums.size();i++){
            if(min_num>nums[i-1])
                min_num=nums[i-1];
            if(max_diff<nums[i]-min_num)
                max_diff=nums[i]-min_num;
        }
        return max_diff>0?max_diff:0;
    }
};